#pragma strict

private var elapsedTime:float = 0;
private var timeToFire:float = 5;
var minTimeToFire:float = 2;
var maxTimeToFire:float = 8;

var speedOfBall:float = 5;

var fireballPrefab:Rigidbody;

function Start () {
	timeToFire = Random.Range(minTimeToFire, maxTimeToFire);
}

function Update () {

	elapsedTime += Time.deltaTime;
	
	if (elapsedTime > timeToFire)
	{
		elapsedTime = 0;
		
		timeToFire = Random.Range(minTimeToFire, maxTimeToFire);
		
		//Fire fireball
		var fireball:Rigidbody = Instantiate(fireballPrefab, transform.position, transform.rotation);
		fireball.rigidbody.AddForce(Vector3(-speedOfBall, 0, 0));
	}
}